from sqlalchemy import String, Integer, Column, ForeignKey
from sqlalchemy.orm import declarative_base, relationship

from .main import engine


Base = declarative_base()

class Task(Base):
    __tablename__ = 'tasks'

    id = Column(Integer, primary_key=True)
    link = Column(String(250))
    number = Column(String(50))
    name = Column(String(250), unique=True)
    complexity = Column(Integer)
    number_of_solutions = Column(Integer)
    topics = relationship(
        'Topic',
        secondary='task_topic',
        back_populates='tasks'
    )

class Topic(Base):
    __tablename__ = 'topics'

    id = Column(Integer, primary_key=True)
    name = Column(String(250), unique=True)
    tasks = relationship(
        'Task',
        secondary='task_topic',
        back_populates='topics'
    )

class TaskTopic(Base):
    __tablename__ = 'task_topic'

    id = Column(Integer, primary_key=True)
    task_id = Column(Integer, ForeignKey('tasks.id'))
    topic_id = Column(Integer, ForeignKey('topics.id'))


Base.metadata.create_all(engine)
